package com.vodone.v1pin.productlist.vo
{
	import mx.collections.ArrayCollection;
	import mx.core.ClassFactory;

	[Bindable]
	public class ProductListVO
	{
		public function ProductListVO( obj:Object = null )
		{
			if( null != obj )
			{
				parseData( obj );
			}
		}
		
		private function parseData( obj:Object ):void
		{
			
			if( obj.hasOwnProperty("currentPage") )
			{
				this.currentPage = obj["currentPage"];
			}
			if( obj.hasOwnProperty("data") )
			{
				this.list = parseList( obj , "data" , ProductItemVO  , 0 , currentPage);
			}
			if( obj.hasOwnProperty("totalCount") )
			{
				this.totalCount = obj["totalCount"];
			}
			if( obj.hasOwnProperty("pageSize") )
			{
				this.pageSize = obj["pageSize"];
			}
			if( obj.hasOwnProperty("activity") )
			{
				this.activity = new ActivityVO( obj["activity"]);
			}
			if( obj.hasOwnProperty("sexlist") )
			{
				this.sexList = parseList( obj , "sexlist" , QueryItemVO );
			}
			if( obj.hasOwnProperty("categorylist") )
			{
				this.typeList = parseList( obj , "categorylist" , QueryItemVO );
			}
			if( obj.hasOwnProperty("pricelist") )
			{
				this.priceList = parseList( obj , "pricelist" , QueryItemVO );
			}
			if( obj.hasOwnProperty("brandlist") )
			{
				this.brandList = parseList( obj , "brandlist" , QueryItemVO );
			}
			if( obj.hasOwnProperty("sizelist") )
			{
				this.sizeList = parseList( obj , "sizelist" , QueryItemVO );
			}
			if( obj.hasOwnProperty("colorlist") )
			{
				this.colorList = parseList( obj , "colorlist" , QueryItemVO );
			}
			if( obj.hasOwnProperty("propertylist") )
			{
				this.propertyList = parseList( obj , "propertylist" , PropertyVO );
			}
			if( obj.hasOwnProperty("recommendCount") )
			{
				this.recommendCount = obj["recommendCount"];
			}
			if( obj.hasOwnProperty("brandinfo") )
			{
				var arr:Array = obj["brandinfo"];
				if( arr && arr.length > 0 )
				{
					this.brandInfo = new BrandInfoVO( arr[0]);
				}
			}
			if( obj.hasOwnProperty("probool") )
			{
				this.probool = Boolean( obj["probool"] );
			}
		}
		
		public static  function parseList( obj:Object , field:String , itemClass:Class , maxCount:int = 0 , page:int = 0  ):ArrayCollection
		{
			var arr:Array = obj[ field ];
			var tempArr:Array = [];
			if( arr && arr.length > 0 )
			{
				var len:int = maxCount > 0 ? Math.min( maxCount , arr.length ) : arr.length;
				for( var i:int = 0 ; i < len ; i++ )
				{
					var item:Object = new itemClass( arr[i] );
//					if( itemClass == ProductItemVO )
//					{
//						item["name"] =  "(" + page +  ":" + i + ")" + item["name"];
//					}
					tempArr.push( item );
				}
			}
			return new ArrayCollection(tempArr);
		}
		
		/**
		 *  false表示没有查询结果
		 */		
		public var probool:Boolean = true;
		/**
		 * 商品列表 
		 */		
		public var list:ArrayCollection;
		/**
		 * 活动 
		 */			
		public var activity:ActivityVO;
		/**
		 * 性别选择条件列表
		 */		
		public var sexList:ArrayCollection;
		/**
		 * 类别列表 
		 */		
		public var typeList:ArrayCollection;
		/**
		 * 品牌选择条件列表
		 */		
		public var brandList:ArrayCollection;
		/**
		 * 价格选择条件列表
		 */		
		public var priceList:ArrayCollection;
		/**
		 * 尺码选择条件列表
		 */		
		public var sizeList:ArrayCollection;
		/**
		 * 颜色选择条件列表
		 */		
		public var colorList:ArrayCollection;
		/**
		 * 属性选择条件列表
		 */		
		public var propertyList:ArrayCollection;
		/**
		 * 一共多少条 
		 */		
		public var totalCount:int;
		/**
		 * 当前第几页
		 */		
		public var currentPage:int;
		/**
		 * 每页大小
		 */		
		public var pageSize:int;
		/**
		 * 推荐商品的总数量 
		 */		
		public var recommendCount:int = 0;
		/**
		 * 品牌信息 
		 */		
		public var brandInfo:BrandInfoVO;
		
	}
}